package com.oa.controller;

import com.oa.pojo.Back;
import com.oa.pojo.Result;
import com.oa.pojo.User;
import com.oa.service.BackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhou
 * @description 针对表【back】接口实现
 * @createDate 2023-10-22
 */
@Api(tags = "销假: 在线接口")
@RestController
@RequestMapping("/back")
public class BackController {
    @Autowired
    private BackService backService;

    @CrossOrigin
    @ApiOperation(value="根据指定id查询销假信息",httpMethod = "GET")
    @GetMapping ("/selectAllByIdBacks")
    public Result selectAllByIdBacks(@RequestBody Back back){
        System.out.println("执行销假查询");
        List<Back> backList = new ArrayList<>();
        backList=backService.selectAllByIdBacks(back);
        if(backList!=null){
            return Result.success(backList);
        }else {
            return Result.error("结果为空");
        }
    }

    @CrossOrigin
    @ApiOperation(value="销假信息更改",httpMethod = "POST",notes = "返回的result类型json格式")
    @PostMapping("/updateBack")
    public Result updateBack(@RequestBody Back back){
        System.out.println("执行修改销假信息");
        int flag=backService.updateBack(back);
        if(flag==1){
            return Result.success();
        }else if (flag==-1){
            return Result.error("-1");
        }else if (flag==-2){
            return Result.error("-2");
        }else if (flag==-3){
            return Result.error("-3");
        }else {
            return Result.error("0");
        }
    }

    @CrossOrigin
    @ApiOperation(value="添加：销假信息",httpMethod = "POST",notes = "返回的result类型json格式")
    @PostMapping("/insertBack")
    public Result insertBack(@RequestBody Back back){
        System.out.println("执行添加销假信息");
        int flag=backService.insertBack(back);
        if(flag==1){
            return Result.success();
        }else if (flag==-1){
            return Result.error("失败");
        }else {
            return Result.error("0");
        }
    }

    @CrossOrigin
    @ApiOperation(value="删除销假信息",httpMethod = "GET",notes = "返回的result类型json格式")
    @GetMapping("/deleteBack")
    public  Result deleteBack(Integer id){
       backService.deleteBack(id);
        return Result.success();
    }
}
